home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14900 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: news.rain.org!usenet
  2. From: "Guus Leeuw jr." <guusl@eiffel.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: delete or delete [] ?
  5. Date: Tue, 02 Apr 1996 08:28:21 -0800
  6. Organization: Interactive Software Engineering Inc. http://www.eiffel.com/
  7. Message-ID: <316155A5.3BA7E96A@eiffel.com>
  8. References: <4jp7n7$f8k@mcmail.CIS.McMaster.CA>
  9. NNTP-Posting-Host: @outback.eiffel.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.8 i586)
  14.  
  15. Hong Shen wrote:
  16. > In almost all of C++ literatures, "delete aa" should be used iff aa is not an
  17. > array and "delete [] aa" should be used iff aa is an array. In following case,
  18. > what should I use?
  19.  
  20. Actually `delete [] aa' should only be used if the array contains non-standard
  21. types. Thus for `int *aa`, you should use `delete aa'.
  22.  
  23. > typedef int int10[10];
  24. > int* aa=new int10; // array of 10 integers.
  25. > delete aa;
  26. > or
  27. > delete [] aa;
  28.  
  29. With the above and the below, this might not work always. I'm not too sure what the
  30. working paper says on this, but I think you can check that yourself :) Or better:
  31. have a look at the FAQ.
  32.  
  33. > For gcc (v2.6), it seems that both work. Which is the standard one?
  34.  
  35. Not really. Last week I came across a `delete [] aa' where the program caught a
  36. SIGSEGV in `end()' after `delete [] mu_ints'. Further investigation taught me to
  37. use `delete my_ints' instead. (I tried the modification and all of a sudden it
  38. worked... :). BTW: I'm using g++ 2.6 as well.
  39.  
  40. -- 
  41. 'l8r,
  42.     Guus
  43. -------------------------------------------------------------------------
  44. They say I'm in need of some radical discipline.
  45.         -- Jim Steinman (from the song: Rock'n'Roll Dreams Come Through)
  46. -------------------------------------------------------------------------
  47.